<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">

    <ui:define name="title">预付记录</ui:define>
    <ui:define name="content">
        <h:form id="prepayForm">
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false"
                      draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton value="新增" actionListener="#{xhhSettlementPrepayListBean.onAdd()}"
                                         oncomplete="PF('adding').show();" process="@this" update="@form"
                                         icon="fa fa-plus">
                        </p:commandButton>
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         actionListener="#{xhhSettlementPrepayListBean.count()}"
                                         update="@form"/>
                        <p:commandButton value="重置" actionListener="#{xhhSettlementPrepayListBean.onReset()}"
                                         icon="fa fa-refresh"
                                         process="@this" update="@form"/>
                        <p:commandButton value="开票" actionListener="#{xhhSettlementPrepayListBean.onBill()}"
                                         icon="fa fa-refresh"
                                         process="@this statisticRecordDataTable"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="预付记录"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 card">
                        <h1>查询条件</h1>
                        <p:panelGrid columns="4" layout="grid"
                                     columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                     styleClass="ui-panelgrid-blank"
                                     style="border:0px none; background-color:transparent;text-align:center;">
                            <p:outputLabel value="主体名称"/>
                            <p:selectOneMenu id="productId" value="#{xhhSettlementPrepayListBean.$.companyId}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{xhhSettlementPrepayListBean.companyList}"
                                               var="dic"
                                               itemLabel="#{dic.companyName}" itemValue="#{dic.id}"/>
                            </p:selectOneMenu>

                            <p:outputLabel value="充值日期"/>
                            <p:outputPanel>
                                <p:calendar
                                        id="startTime" styleClass="autoWidthCalendar"
                                        value="#{xhhSettlementPrepayListBean.$.startTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                                <span>— </span>
                                <p:calendar
                                        id="endTime" styleClass="autoWidthCalendar"
                                        value="#{xhhSettlementPrepayListBean.$.endTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                            </p:outputPanel>

                            <p:outputLabel value="开票状态"/>
                            <p:selectOneMenu id="billStatus" value="#{xhhSettlementPrepayListBean.$.billStatus}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItem itemLabel="未开票" itemValue="0"/>
                                <f:selectItem itemLabel="财务专员审核中" itemValue="1"/>
                                <f:selectItem itemLabel="财务经理审核中" itemValue="2"/>
                                <f:selectItem itemLabel="已开票" itemValue="3"/>
                            </p:selectOneMenu>

                            <p:outputLabel value="付款方式"/>
                            <p:selectOneMenu value="#{xhhSettlementPrepayListBean.$.payMode}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{xhhSettlementPrepayListBean.dictionaries[DictionaryCode.XHH_SETTLEMENT_PAY_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>

                            <p:outputLabel value="支付账号"/>
                            <p:inputText id="payAccount" value="#{xhhSettlementPrepayListBean.$.payAccount}"/>

                            <p:outputLabel value="创建人"/>
                            <p:inputText id="creator" value="#{xhhSettlementPrepayListBean.$.creator}"/>

                        </p:panelGrid>
                    </div>
                    <div style="background-color: #ffffff; height: 40px;float: left;width: 100%;">
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="订单总额"/>
                        </div>
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="银行卡成交额"/>
                        </div>
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="微信成交额"/>
                        </div>
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="支付宝成交额" style="text-align: center"/>
                        </div>
                    </div>
                        <div style="background-color: #ffffff; height: 40px;float: left;width: 100%;">
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="#{xhhSettlementPrepayListBean.toTalOrderCount}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </p:outputLabel>
                        </div>
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="#{xhhSettlementPrepayListBean.bankOrderCount}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </p:outputLabel>
                        </div>
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="#{xhhSettlementPrepayListBean.wechatOrderCount}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </p:outputLabel>
                        </div>
                        <div class="ui-g-3" style="text-align: center;font-size: 30px;padding-top: 0px;font-weight: normal">
                            <p:outputLabel value="#{xhhSettlementPrepayListBean.aliOrderCount}">
                                <f:convertNumber pattern="#,##0.00"/>
                            </p:outputLabel>
                        </div>
                    </div>
                    <div class="ui-g-12 card">
                        <p:dataTable id="statisticRecordDataTable"
                                     style="width: 100%;text-align:center"
                                     var="record"
                                     value="#{xhhSettlementPrepayListBean.lazyDataModel}"
                                     rows="#{constants:get('ROWS')}"
                                     lazy="true"
                                     paginator="true"
                                     paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                     rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                     emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                     scrollable="true"
                                     scrollWidth="97%"
                                     reflow="true"
                                     selection="#{xhhSettlementPrepayListBean.selectPrepayList}" rowKey="#{record.id}"
                                     resizableColumns="true">
                            <p:column selectionMode="multiple" style="width:17px;text-align:center" exportable="false"/>
                            <p:column headerText="核对" exportable="false" rendered="#{security:areAllGranted('BUSINESS_SECURITY_STATUS')}" style="width: 70px">
                                <p:commandButton icon="fa fa-refresh" value="核对" style="width: 70px"
                                                 process="@this"
                                                 actionListener="#{xhhSettlementPrepayListBean.onStatus(record.id)}"
                                                 update="@form">
                                    <p:confirm header="提示信息" message="是否确定核对?" icon="ui-icon-alert"/>
                                </p:commandButton>
                            </p:column>
                            <p:column headerText="操作" exportable="false" style="width: 70px">
                                <p:splitButton icon="fa fa-eye"
                                               process="@this"
                                               actionListener="#{xhhSettlementPrepayListBean.onSee(record.id)}"
                                               oncomplete="PF('adding').show();" update="@form">
                                    <f:setPropertyActionListener
                                            value="/views/settlementsystem/prepay-list.xhtml"
                                            target="#{currentUserBean.back}"/>

                                    <p:menuitem value="删除" icon="fa fa-remove"
                                                rendered="#{security:areAllGranted('LOAN_SETTLEMENT_PREPAY_DELETE')}"
                                                actionListener="#{xhhSettlementPrepayListBean.onDelete(record.id, record.billStatus)}"
                                                process="@this" update="@form">
                                        <p:confirm header="提示信息" message="是否确定删除?" icon="ui-icon-alert"/>
                                    </p:menuitem>
                                </p:splitButton>
                            </p:column>
                            <p:column headerText="充值日期" style="width: 100px">
                                <h:outputText value="#{record.prepayTime}"/>
                            </p:column>
                            <p:column headerText="主体唯一id" style="width: 50px">
                                <h:outputText value="#{record.companyId}"/>
                            </p:column>
                            <p:column headerText="主体名称" style="width: 250px">
                                <h:outputText value="#{record.companyName}"/>
                            </p:column>
                            <p:column headerText="付款方式" style="text-align:center;width: 70px">
                                <h:outputText
                                        value="#{xhhSettlementPrepayListBean.translate(DictionaryCode.XHH_SETTLEMENT_PAY_MODE,record.payMode)}"/>
                            </p:column>
                            <p:column headerText="充值金额" style="text-align:center;width: 80px">
                                <h:outputText
                                        value="#{record.prepayAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="支付账户" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.payName}"/>
                            </p:column>
                            <p:column headerText="支付账号" style="text-align:center;width: 100px">
                                <h:outputText
                                        value="#{record.payAccount}"/>
                            </p:column>
                            <p:column headerText="核对状态" style="text-align:center;width: 80px">
                                <h:outputText value="未核对" rendered="#{record.prepayStatus!=1}" style="color: red"/>
                                <h:outputText value="已核对" rendered="#{record.prepayStatus==1}" style="color: blue"/>
                            </p:column>
                            <p:column headerText="开票状态" style="text-align:center;width: 100px">
                                <h:outputText value="未开票" rendered="#{record.billStatus==0}" style="color: red"/>
                                <h:outputText value="财务专员审核中" rendered="#{record.billStatus==1}"
                                              style="color: olivedrab"/>
                                <h:outputText value="财务经理审核中" rendered="#{record.billStatus==2}"
                                              style="color: olivedrab"/>
                                <h:outputText value="已开票" rendered="#{record.billStatus==3}" style="color: blue"/>
                            </p:column>
                            <p:column headerText="创建人" style="text-align:center;width: 100px">
                                <h:outputText value="#{record.creator}"/>
                            </p:column>
                            <p:column headerText="创建时间" style="text-align:center;width: 150px">
                                <h:outputText value="#{record.createTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </div>
                </div>
            </div>
            <p:dialog header="预付记录" widgetVar="adding" modal="true" closable="true"
                      resizable="true"
                      style="position: absolute;">
                <p:outputPanel id="add-dialog">
                    <div class="ui-g ui-fluid" style="width:1000px;">
                        <div class="ui-g-2">
                            <p:outputLabel value="主体名称"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu value="#{xhhSettlementPrepayListBean.settlementPrepay.companyId}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{xhhSettlementPrepayListBean.companyList}"
                                               var="dic"
                                               itemLabel="#{dic.companyName}" itemValue="#{dic.id}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="充值日期"/>
                        </div>
                        <div class="ui-g-4">
                            <p:calendar
                                    value="#{xhhSettlementPrepayListBean.settlementPrepay.prepayTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}">
                            </p:calendar>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="充值金额"/>
                        </div>
                        <div class="ui-g-4">
                            <p:inputNumber value="#{xhhSettlementPrepayListBean.settlementPrepay.prepayAmount}">
                            </p:inputNumber>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="付款方式"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu value="#{xhhSettlementPrepayListBean.settlementPrepay.payMode}">
                                <p:ajax event="change" process="@this" update="pay-panel"/>
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{xhhSettlementPrepayListBean.dictionaries[DictionaryCode.XHH_SETTLEMENT_PAY_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <p:outputPanel id="pay-panel" styleClass="ui-g-12 padding0">
                            <div class="ui-g-2">
                                <p:outputLabel
                                        value="#{xhhSettlementPrepayListBean.settlementPrepay.payMode == 1?'支付宝账户':'银行卡账户'}"/>
                            </div>
                            <div class="ui-g-4">
                                <p:inputText value="#{xhhSettlementPrepayListBean.settlementPrepay.payName}"/>
                            </div>
                            <div class="ui-g-2">
                                <p:outputLabel
                                        value="#{xhhSettlementPrepayListBean.settlementPrepay.payMode == 1?'支付宝账号':'银行卡账号'}"/>
                            </div>
                            <div class="ui-g-4">
                                <p:inputText value="#{xhhSettlementPrepayListBean.settlementPrepay.payAccount}"/>
                            </div>
                        </p:outputPanel>


                        <div class="ui-g-12" style="padding: 0">
                            <div class="ui-g-2">
                                <p:outputLabel value="备注"/>
                            </div>
                            <div class="ui-g-10">
                                <p:inputText value="#{xhhSettlementPrepayListBean.settlementPrepay.remark}"/>
                            </div>
                        </div>

                        <div class="ui-g-12">
                            <p:commandButton value="保存" style="float: right"
                                             actionListener="#{xhhSettlementPrepayListBean.onSave()}"
                                             process="@this add-dialog"/>
                        </div>
                    </div>
                </p:outputPanel>
            </p:dialog>
            <ui:include src="prepay-bill-dialog.xhtml"/>
        </h:form>
    </ui:define>
</ui:composition>